#include "../include/header.h"
#include "14_forteen.cpp"

void ExchangeSon(BinaryTreeNode *root)
{
    if (NULL == root)
        return;

    BinaryTreeNode *temp = root->m_pLeft;
    root->m_pLeft = root->m_pRight;
    root->m_pRight = temp;

    if (root->m_pLeft)
        ExchangeSon(root->m_pLeft);


    if (root->m_pRight)
        ExchangeSon(root->m_pRight);

}


//            1
//          /  \
//         2    3
//             /  \
//            4    5
//           / \    \
//         6    7    8
//                     \
//                      9
//                        \
//                         10

void TestForFifteen()
{
    BinaryTreeNode* node1 = CreateTreeNode(1);
    BinaryTreeNode* node2 = CreateTreeNode(2);
    BinaryTreeNode* node3 = CreateTreeNode(3);
    BinaryTreeNode* node4 = CreateTreeNode(4);
    BinaryTreeNode* node5 = CreateTreeNode(5);
    BinaryTreeNode* node6 = CreateTreeNode(6);
    BinaryTreeNode* node7 = CreateTreeNode(7);
    BinaryTreeNode* node8 = CreateTreeNode(8);
    BinaryTreeNode* node9 = CreateTreeNode(9);
    BinaryTreeNode* node10 = CreateTreeNode(10);

    ConnectTreeNodes(node1, node2, node3);
    ConnectTreeNodes(node3, node4, node5);
    ConnectTreeNodes(node4, node6, node7);
    ConnectTreeNodes(node5, NULL, node8);

    ConnectTreeNodes(node8, NULL, node9);
    ConnectTreeNodes(node9, NULL, node10);

    cout << "The tree before exchange is :" << endl;
    PrintTreeByLevel(node1);
    ExchangeSon(node1);
    cout << "The tree after exchange is :" << endl;
    PrintTreeByLevel(node1);
}
